<template>
  <!-- 来料检任务清单 -->
  <p-card :bordered="false">
    <p-page-header
            style="border: 1px solid rgb(235, 237, 240)"
            :title="title"
    >
      <template slot="extra">

        <p-button key="1" type="primary" @click="saveDataBtn">
          保存
        </p-button>

        <p-popconfirm
                title="确定要提交吗？"
                ok-text="确定"
                cancel-text="取消"
                @confirm="submitData"
                @cancel="cancel"
        >
          <p-button type="primary">提交</p-button>
        </p-popconfirm>

        <p-button key="1" type="danger" @click="saveDataBtn">
          产品锁定
        </p-button>

        <p-button key="1" type="danger" @click="saveDataBtn">
          异常记录
        </p-button>
        <p-button @click="backToIndex">取消</p-button>
      </template>
    </p-page-header>

    <p-form-model
            ref="baseInfoData"
            :model="baseInfoData"
            :rules="rules"
            :label-col="labelCol"
            :wrapper-col="wrapperCol"
    >
    <p-collapse v-model="activeKey" >
      <p-collapse-panel key="1" header="基础信息"  >
        <p-row :gutter="24">
          <p-col :span="8">
            <p-form-model-item ref="inspectBillno" label="送检单号" prop="inspectBillno">
              <p-input
                      readOnly
                      v-model="baseInfoData.inspectBillno"
                      @blur="
          () => {
            $refs.inspectBillno.onFieldBlur();
          }
        "
              />
            </p-form-model-item>
          </p-col>
          <p-col :span="8">
            <p-form-model-item ref="processBillno" label="工序工单" prop="processBillno">
              <p-input
                      readOnly
                      v-model="baseInfoData.processBillno"
                      @blur="
          () => {
            $refs.processBillno.onFieldBlur();
          }
        "
              >
                <p-tooltip slot="suffix" :title="baseInfoData.processBillno">
                  <p-icon type="info-circle" style="color: rgba(0,0,0,.45)" />
                </p-tooltip>
              </p-input>
            </p-form-model-item>
          </p-col>
          <p-col :span="8">
            <p-form-model-item ref="mcode" label="产品编号" prop="mcode">
              <p-input
                      readOnly
                      v-model="baseInfoData.mcode"
                      @blur="
          () => {
            $refs.mcode.onFieldBlur();
          }
        "
              />
            </p-form-model-item>
          </p-col>
          <p-col :span="8">
            <p-form-model-item ref="mname" label="产品名称" prop="mname">
              <p-input
                      readOnly
                      v-model="baseInfoData.mname"
                      @blur="
          () => {
            $refs.mname.onFieldBlur();
          }
        "
              >
                <p-tooltip slot="suffix" :title="baseInfoData.mname">
                  <p-icon type="info-circle" style="color: rgba(0,0,0,.45)" />
                </p-tooltip>
              </p-input>
            </p-form-model-item>
          </p-col>
          <p-col :span="8">
            <p-form-model-item ref="processTwo" label="二级工序" prop="processTwo">
              <p-input
                      readOnly
                      v-model="baseInfoData.processTwo"
                      @blur="
          () => {
            $refs.processTwo.onFieldBlur();
          }
        "
              />
            </p-form-model-item>
          </p-col>
          <p-col :span="8">
            <p-form-model-item ref="linename" label="线体" prop="linename">
              <p-input
                      readOnly
                      v-model="baseInfoData.linename"
                      @blur="
          () => {
            $refs.linename.onFieldBlur();
          }
        "
              >
                <p-tooltip slot="suffix" :title="baseInfoData.linename">
                  <p-icon type="info-circle" style="color: rgba(0,0,0,.45)" />
                </p-tooltip>
              </p-input>
            </p-form-model-item>
          </p-col>
          <p-col :span="8">
            <p-form-model-item ref="sendTime" label="送检时间" prop="sendTime">
              <p-input
                      readOnly
                      v-model="baseInfoData.createTime"
                      @blur="
          () => {
            $refs.sendTime.onFieldBlur();
          }
        "
              />
            </p-form-model-item>
          </p-col>
          <p-col :span="8">
            <p-form-model-item ref="simpleMethod" label="抽样方式" prop="simpleMethod">
              <p-input
                      readOnly
                      v-model="baseInfoData.simpleMethod"
                      @blur="
          () => {
            $refs.simpleMethod.onFieldBlur();
          }
        "
              />
            </p-form-model-item>
          </p-col>
          <p-col :span="8">
            <p-form-model-item ref="simpleQty" label="抽样数量" prop="simpleQty">
              <p-input
                      readOnly
                      v-model="baseInfoData.simpleQty"
                      @blur="
          () => {
            $refs.simpleQty.onFieldBlur();
          }
        "
              />
            </p-form-model-item>
          </p-col>
          <p-col :span="8">
            <p-form-model-item ref="inspecter" label="检验人" prop="inspecter">
              <p-input
                      readOnly
                      v-model="baseInfoData.inspecter"
                      @blur="
          () => {
            $refs.inspecter.onFieldBlur();
          }
        "
              />
            </p-form-model-item>
          </p-col>
          <p-col :span="8">
            <p-form-model-item ref="inspectTime" label="检验时间" prop="inspectTime">
              <p-input
                      readOnly
                      v-model="baseInfoData.inspectTime"
                      @blur="
          () => {
            $refs.inspectTime.onFieldBlur();
          }
        "
              />
            </p-form-model-item>
          </p-col>



        </p-row>
      </p-collapse-panel>


      <p-collapse-panel v-if="visible==1" key="2" header="抽检SN明细"  >
        <p-table
                v-if="visible==1"
                :columns="simpleSNDetailColumns"
                :data-source="baseInfoData.mesQcTourinspSnDetailList"
                class="components-table-demo-nested"
                bordered
                style="margin-top:10px;"
        >
          <template slot="inspectProjectId" slot-scope="text,record">
            <p-select v-model="record.inspectProjectId" placeholder="please select your zone" @change="inspectProjectSelectChange">
              <p-select-option
                      v-for="(item) in record.inspectProjectList"
                      :key="index"
                      :value="item.inspectProjectId"
              >{{item.inspectProject}}</p-select-option>
            </p-select>
          </template>

          <template slot="remark" slot-scope="text,record">
            <p-textarea v-model="record.remark" :rows="2" />
          </template>


          <template slot="operation" slot-scope="text,record">
            <p-popconfirm
                    title="确定要删除此项？"
                    ok-text="删除"
                    cancel-text="取消"
                    @confirm="deleteSimpleSNDetail(record)"
            >
              <a href="#">删除</a>
            </p-popconfirm>
          </template>

        </p-table>
      </p-collapse-panel>

      <p-collapse-panel v-if="visible==1" key="3" header="检验项目"  >
        <p-table
                v-if="visible==1"
                :columns="checkProjectColumns"
                :data-source="baseInfoData.mesQcTourinspProjectsList"
                class="components-table-demo-nested"
                bordered
                style="margin-top:10px;"
        >
          <template slot="measuredValue" slot-scope="text,record">

            <p-select v-if="record.valueType==2" v-model="record.measuredValue" placeholder="please select your zone" @change="measuredValueSelectChange">
              <p-select-option
                      v-for="(item,index) in passNgOptions"
                      :key="index"
                      :value="item.value"
              >{{item.name}}</p-select-option>
            </p-select>
            <p-input type="number" v-else  v-model="record.measuredValue "  @change="measuredValueInputChange"/>
          </template>

        </p-table>
      </p-collapse-panel>


      <p-collapse-panel v-if="visible==2" key="2" header="检验项目"  >
        <p-table
                v-if="visible==2"
                :columns="modal1InspectionColumns"
                :data-source="baseInfoData.mesQcTourinspLinemList"
                class="components-table-demo-nested"
                bordered
                :expandIcon="expandIcon"
                style="margin-top:10px;"
        >
          <a slot="photoUrl" slot-scope="text">photoUrl</a>




          <p-table
                  slot="expandedRowRender"
                  slot-scope="text"
                  :columns="modal1InspectionInnerColumns"
                  :data-source="text.mesQcTourinspProjectsList"
                  :pagination="false"

                  bordered
          >

            <template slot="measuredValue" slot-scope="text,record">

              <p-select v-if="record.valueType==2" v-model="record.measuredValue" placeholder="please select your zone" @change="measuredValueSelectChange2">
                <p-select-option
                        v-for="(item,index) in passNgOptions"
                        :key="index"
                        :value="item.value"
                >{{item.name}}</p-select-option>
              </p-select>
              <p-input type="number" v-else  v-model="record.measuredValue "  @change="measuredValueInputChange2"/>
            </template>
          </p-table>
        </p-table>
      </p-collapse-panel>

    </p-collapse>

      <h4 class="title" >质量判定</h4>

      <p-row>
        <p-col :span="8">
          <p-form-model-item ref="inspectResult" label="检验结论" prop="inspectResult" >
            <p-tag v-if="baseInfoData.inspectResult==1" color="green"><p-icon type="check-circle" />合格</p-tag>
            <p-tag v-else-if="baseInfoData.inspectResult==2" color="red"><p-icon type="close-circle" />不合格</p-tag>

          </p-form-model-item>
        </p-col>

        <p-col :span="8">
          <p-form-model-item ref="changeCondition" label="整改情况" prop="changeCondition">
            <p-input
                    v-model="baseInfoData.changeCondition"
            />
          </p-form-model-item>
        </p-col>

      </p-row>

    </p-form-model>
  </p-card>
</template>

<script>

  import Operation1 from "@/components/mesCom/mesQc/MesQcTourInspectOperation/Operation1.vue";
  import Operation2 from "@/components/mesCom/mesQc/MesQcTourInspectOperation/Operation2.vue";
  import {getAction, postAction, deleteAction, putAction} from "../../../api/manage";
  import dayjs from "dayjs";


  export default {
    name: "MesQcTourInspectReview",
    props:['mqVisible','mqLoad','mqData'],
    data() {
      return {
        labelCol: { span: 8 },
        wrapperCol: { span: 14 },

        activeKey:['1','2','3'],
        visible:1,  //通过设置visible的值（1或者2）来显示不同类型的检验操作
        title:'',
        //新增行弹出框
        addCPModalVisible:false,
        templateList:[],
        templateListDetails:[],
        selectedRowKeysArray:[],
        selectedRows:[],
        selectedType:1,
        inspectMethodList:[],
        inspectMethodMap:[],
        standardUnitList:[],
        standardUnitMap:[],

        // 进料检验类型数据
        modal1InspectionColumns: [
          {
            title: "序号",
            dataIndex: "key",
            customRender: function (t, r, index) {
              return parseInt(index) + 1;
            },
          },
          { title: "线号/组件编号", dataIndex: "lineBillno", key: "lineBillno" },
          { title: "物料编码", dataIndex: "mcode", key: "mcode" },
          { title: "物料名称", dataIndex: "mname", key: "mname" },
          { title: "物料一级分类", dataIndex: "productOneType", key: "productOneType" },
          { title: "物料二级分类", dataIndex: "productTwoType", key: "productTwoType" },
          { title: "物料三级分类", dataIndex: "productThreeType", key: "productThreeType" },

          { title: "检验结果",
            dataIndex: "inspectResult",
            key: "inspectResult",
            customRender: (text) => {
              if (!text) {
                return "";
              } else {
                return text==1?'合格':'不合格';
              }
            },
          },
          {
            title: "图片",
            key: "photoUrl",
            scopedSlots: { customRender: "photoUrl" },
          },

        ],

        modal1InspectionInnerColumns: [
          {
            title: "序号",
            dataIndex: "key",
            customRender: function (t, r, index) {
              return parseInt(index) + 1;
            },

          },
          { title: "检验项目", dataIndex: "inspectProject", key: "inspectProject" },
          {
            title: "检验标准",
            dataIndex: "inpectStandard",
            key: "inpectStandard",
          },
          {
            title: "值类型",
            key: "valueType",
            customRender: (text) => {
              if (!text) {
                return "";
              } else {
                return text==1?'计量型':'计数型';
              }
            },
          },
          { title: "标准值", dataIndex: "standardValue", key: "standardValue" },
          {
            title: "上限值",
            dataIndex: "upperValue",
            key: "upperValue",

          },
          { title: "下限值", dataIndex: "downValue", key: "downValue" },
          { title: "参数", dataIndex: "param", key: "param" },
          {
            title: "实测值",
            dataIndex: "measuredValue",
            key: "measuredValue",
            scopedSlots: { customRender: "measuredValue" },
          },
          {
            title: "单项判定",
            dataIndex: "individualJudgment",
            key: "individualJudgment",
            customRender: (text) => {
              if (!text) {
                return "";
              } else {
                return text==1?'PASS':'NG';
              }
            },
          },


        ],

        templateListColumns:[
          { title: "线号/组件编号", dataIndex: "sample", key: "sample" },
          { title: "物料编码", dataIndex: "mcode", key: "mcode" },
          { title: "物料名称", dataIndex: "mname", key: "mname" },
        ],
        templateListDetailsColumns:[
          { title: "检验项目", dataIndex: "inspectProject", key: "inspectProject" },
          { title: "检验标准", dataIndex: "inspectStatand", key: "inspectStatand" },
          { title: "值类型", dataIndex: "valueType", key: "valueType",
            customRender: (text) => {
              if (!text) {
                return "";
              } else {
                return text==1?'计量型':'计数型';
              }
            },
          },
          { title: "标准值", dataIndex: "standardValue", key: "standardValue" },
          { title: "上限值", dataIndex: "upperValue", key: "upperValue" },
          { title: "下限值", dataIndex: "downValue", key: "downValue" },
        ],

        passNgOptions:[
          {
            name: "PASS",
            value: "PASS",
          },
          {
            name: "NG",
            value: "NG",
          },
        ],
        measuredValueOptions: [
          {
            name: "pass",
            value: 1,
          },
          {
            name: "NG",
            value: 2,
          },
        ],
        checkProjectColumns:[
          {
            title: "序号",
            dataIndex: "",
            key: "rowIndex",
            width: 60,
            align: "center",
            customRender: function (t, r, index) {
              return parseInt(index) + 1;
            },
          },
          { title: "工站", dataIndex: "workStation", key: "workStation" },
          { title: "检验项目", dataIndex: "inspectProject", key: "inspectProject" },
          { title: "检验标准", dataIndex: "inspectStatand", key: "inspectStatand" },
          { title: "值类型", dataIndex: "valueType", key: "valueType",
            customRender: (text) => {
              if (!text) {
                return "";
              } else {
                return text==1?'计量型':'计数型';
              }
            },
          },
          { title: "检验手段",
            dataIndex: "inspectMethod",
            key: "inspectMethod",
            customRender:(text)=>{
              if(!text){
                return '';
              }else{
                return this.inspectMethodMap[text].title
              }

            }
          },


          { title: "标准值", dataIndex: "standardValue", key: "standardValue", scopedSlots: { customRender: "standardValue" }, },
          { title: "单位",
            dataIndex: "standardUnit",
            key: "standardUnit",
            customRender:(text)=>{
              return this.standardUnitMap[text]?this.standardUnitMap[text].title:''
            }
          },
          {
            title: "上限值",
            dataIndex: "upperValue",
            key: "upperValue",
            scopedSlots: { customRender: "upperValue" },
          },
          { title: "下限值", dataIndex: "downValue", key: "downValue" , scopedSlots: { customRender: "downValue" },},
          { title: "参数", dataIndex: "param", key: "param" },
          {
            title: "实测值",
            dataIndex: "measuredValue",
            key: "measuredValue",
            scopedSlots: { customRender: "measuredValue" },
          },
          {
            title: "单项判定",
            dataIndex: "individualJudgment",
            key: "individualJudgment",
            customRender: (text) => {
              if (!text) {
                return "";
              } else {
                return text==1?'PASS':'NG';
              }
            },
          },
        ],
        checkProjectData:[],
        simpleSNDetailColumns:[
          {
            title: "序号",
            dataIndex: "",
            key: "rowIndex",
            width: 60,
            align: "center",
            customRender: function (t, r, index) {
              return parseInt(index) + 1;
            },
          },
          {
            title: "SN",
            dataIndex: "sn",
          },
          {
            title: "检验项目",
            dataIndex: "inspectProjectId",
            scopedSlots: {customRender: "inspectProjectId"},
          },
          {
            title: "图片",
            dataIndex: "photoUrl",
          },
          {
            title: "备注",
            dataIndex: "remark",
            scopedSlots: {customRender: "remark"},
          },

        ],
        simpleSNDetailData:[],

        baseInfoData: {
          //基础信息
          inspectBillno: "001", //送检单号
          processBillno: "", //工序工单
          mcode: "001", //产品编号
          mname: "", //产品名称
          processTwo: "", //二级工序
          linename: "", //线体
          createTime: "", //送检时间
          simpleMethod: "", //抽样方式
          simpleQty: "3", //抽样数量
          inspecter: "", //检验人
          inspectTime: "", //检验时间
          sn: "", //sn
          changeCondition:'',
          inspectResult: 1,
        },

        rules: {
          inspectBillno: [
            {
              required: true,
              message: "Please input Activity name",
              trigger: "blur",
            },
          ],
          processBillno: [
            {
              required: true,
              message: "Please input Activity name",
              trigger: "blur",
            },
          ],
          mcode: [
            {
              required: true,
              message: "Please input Activity name",
              trigger: "blur",
            },
          ],
          mname: [
            {
              required: true,
              message: "Please input Activity name",
              trigger: "blur",
            },
          ],
          processTwo: [
            {
              required: true,
              message: "Please input Activity name",
              trigger: "blur",
            },
          ],
          linename: [
            {
              required: true,
              message: "Please input Activity name",
              trigger: "blur",
            },
          ],
          createTime: [
            {
              required: true,
              message: "Please input Activity name",
              trigger: "blur",
            },
          ],
          simpleMethod: [
            {
              required: true,
              message: "Please input Activity name",
              trigger: "blur",
            },
          ],
          simpleQty: [
            {
              required: true,
              message: "Please input Activity name",
              trigger: "blur",
            },
          ],
          inspecter: [
            {
              required: true,
              message: "Please input Activity name",
              trigger: "blur",
            },
          ],
          inspectTime: [
            {
              required: true,
              message: "Please input Activity name",
              trigger: "blur",
            },
          ],

        },




      };
    },
    components: {

    },


    computed: {

    },

    created() {
    this.mqListener();
      this.initInspectMethodList();
      this.initStandardUnitList();
    },

    methods: {
      mqListener(){
        console.log(this.mqVisible)
        console.log(this.mqLoad)
        console.log(this.mqData)
        this.initData(this.mqData);
      },
      backToIndex(){
        let mqData = this.mqData;
        this.$emit('update:mqVisible', 1);
        this.$emit('update:mqLoad', false);
        mqData.id = 0;
        mqData.isPallet = "";
        mqData.inspectStatus = "";
        this.$emit('update:mqData', mqData);
      },
      /**
       * 展开图标
       * @param props
       * @returns {string|*}
       */
      expandIcon(props){
        if(props.record.mesQcTourinspProjectsList&&props.record.mesQcTourinspProjectsList.length>0){

          if (props.expanded) {
            return <p-icon type='minus-square' onClick={e => {props.onExpand(props.record, e);}}/>;
          }else{
            return <p-icon type='plus-square' onClick={e => {props.onExpand(props.record, e);}}/>;
          }

        }else{
          return "";
        }
      },
      //加载数据
      initData(query){
        if(!query.id){
          this.$message.warning("请通过巡检任务清单选择单号进入！");
        }else {
          let id = query.id;
          let isPallet = query.isPallet;
          if(isPallet==1){
            this.title='巡检操作（线材预制）';
            this.visible = 2;
          }else{
            this.title='巡检操作';
            this.visible = 1;
          }

          getAction('/mes-quality/mesQcTourInspectTask/selectById',{id:id}).then(res=>{
            if (res.success) {
              if(res.code!=0){
                this.$message.warning(res.msg)
              }
              let data = res.data;
              data.createTime = dayjs(data.createTime).format("YYYY-MM-DD HH:mm:ss")
              this.baseInfoData = data;
              this.dataSet();
            } else {
              this.$message.warning("后台获取单据信息报错");
            }
          })
        }

      },

      initStandardUnitList(){
        getAction('/basic-business/sys/dict/queryDictItemsByCode',{dictCode:'mes_details_tamplate_unit'}).then(res=>{
          if(res.success){
            this.standardUnitList = res.data;
            this.standardUnitMap = this.listToMap(this.standardUnitList,'value');
          }
        })
      },
      initInspectMethodList(){
        getAction('/basic-business/sys/dict/queryDictItemsByCode',{dictCode:'mes_inspect_method'}).then(res=>{
          if(res.success){
            this.inspectMethodList = res.data;
            this.inspectMethodMap = this.listToMap(this.inspectMethodList,'value');
          }
        })
      },

      /**
       * 点击‘新增行’按钮
       */
      addCheckProjectBtn(){
        this.addCPModalVisible = true;
      },


      /**
       * 确定添加
       */
      sureAddCheckProject(){
        let data = this.selectedRows[0];
        data.mesQcTourinspProjectsList = data.templateList;
        data.mesPitId = this.baseInfoData.id;
        putAction('/mes-quality/mesQcTourInspectTask/addLinemInspectProject',data).then(res=>{
          if(res.success){
            this.$message.success("新增成功！");
            this.resetRadioSelect();
            this.addCPModalVisible = false;
            this.initData();
          }else{
            this.$message.warning("新增失败！");
          }
        })
      },

      /**
       * 取消-关闭modal
       */
      closeAddCPModal(){
        this.resetRadioSelect();
        this.addCPModalVisible = false;
      },

      /**
       *加载检验项目列表
       */
      initSampleTemplateList(sendBillno){

        getAction('/mes-quality/mesQcIncomeBasicInfo/querySampleTemplateList/'+ sendBillno).then(res=>{

          if (res.success) {
            let data = res.data;
            this.templateList = data;
          } else {
            this.$message.warning("后台获取检验项目列表报错");
          }
        })
      },

      /**
       * 重设radio
       */
      resetRadioSelect(){
        this.selectedRowKeysArray = [];
        this.selectedRows = [];
        this.templateListDetails = [];
        this.selectedType = 1;
      },

      /**
       * 检验项目单选框change事件
       */
      onSelectChange(selectedRowKeys, selectedRows){
        this.selectedRowKeysArray = selectedRowKeys;
        this.selectedRows = selectedRows;
        this.templateListDetails = selectedRows[0].templateList;
        if(this.templateListDetails.length>0){
          this.selectedType=2
        }else{
          this.selectedType=3
        }
      },

      dataSet(){
        if(this.visible==1){
          //非线材
          this.baseInfoData.mesQcTourinspSnDetailList.forEach(item=>{
            item.inspectProjectList = [
              {inspectProjectId:123,inspectProject:'123'},
              {inspectProjectId:456,inspectProject:'456'},
              {inspectProjectId:234,inspectProject:'234'},
              {inspectProjectId:789,inspectProject:'789'},
            ];
          })

        }else{
          this.initSampleTemplateList('a');
        }

        this.checkProjectDataReset();
      },

      //删除抽检sn明细
      deleteSimpleSNDetail(record){

        let data ={
          sendInspectSnId:record.id,
          taskId:this.baseInfoData.id
        }

        postAction('/mes-quality/mesQcTourInspectTask/deleteTourSendProductDetail',data).then(res=>{
          if(res.success){
            this.$message.success("删除成功！");
            let listData = res.data;
            this.baseInfoData.mesQcTourinspSnDetailList = listData;
          }else{
            this.$message.error("删除失败！")
          }
        })
      },

      //抽检sn明细下拉框变更
      inspectProjectSelectChange(){

        this.baseInfoData.mesQcTourinspSnDetailList.forEach(item=>{
          let inspectProjectId = item.inspectProjectId;
          if(item.inspectProjectList&&item.inspectProjectList.length>0){
            let map = this.listToMap(item.inspectProjectList,'inspectProjectId');
            if(map[inspectProjectId]){
              item.inspectProject = map[inspectProjectId].inspectProject;
            }
          }

        })

      },

      //封装listToMap
      listToMap(list,name){
        let map = {};
        for(let i in list){
          map[list[i][name]] = list[i];
        }
        return map;
      },

      //sn回车事件
      snPressEnter(e){
        let sn = this.baseInfoData.sn;
        let flag = true;

        if(!sn||sn===''){
          flag = false;
          this.$message.error("SN不能为空！")
        }else{
          if (sn.trim()=='') {
            flag = false;
            this.$message.error("SN不能为纯空格的字符串！")
          }
        }

        if(flag){
          let data ={
            taskId:this.baseInfoData.id,
            sn:sn
          }
          postAction('/mes-quality/mesQcTourInspectTask/addTourSendProductDetail',data).then(res=>{
            if(res.success){
              this.$message.success("新增SN成功！");
              let listData = res.data;
              this.baseInfoData.mesQcTourinspSnDetailList = listData;
            }else{
              this.$message.error("新增SN失败！")
            }
          })
        }




      },

      //实测值-下拉框change事件
      measuredValueSelectChange(){
        this.checkProjectDataReset();
      },
      measuredValueSelectChange2(){
        this.checkProjectDataReset();
      },

      //实测值输入框change事件
      measuredValueInputChange(){
        this.checkProjectDataReset();
      },
      measuredValueInputChange2(){
        this.checkProjectDataReset();
      },

      //检验项目表联动重置-用于非线材预制
      checkProjectDataReset(){
        let resultFlag = true;
        if(this.visible==1){
          if(this.baseInfoData.mesQcTourinspProjectsList){
            this.baseInfoData.mesQcTourinspProjectsList.forEach(item=>{
              let measuredValue  = item.measuredValue;
              if(item.valueType==2){
                item.individualJudgment =measuredValue=='PASS'?1:2;
              }else{
                if((item.upperValue&&item.upperValue!='')&&(!item.downValue||item.downValue=="")){
                  if(measuredValue<=item.upperValue){
                    item.individualJudgment = 1;
                  }else{
                    item.individualJudgment = 2;

                    resultFlag = false;
                  }
                }else if((!item.upperValue||item.upperValue=='')&&(item.downValue&&item.downValue!="")){
                  if(measuredValue>=item.downValue){
                    item.individualJudgment = 1;
                  }else{
                    item.individualJudgment = 2;

                    resultFlag = false;
                  }
                }else if(measuredValue<=item.upperValue&&measuredValue>=item.downValue){
                  item.individualJudgment = 1;
                }else{
                  item.individualJudgment = 2;

                  resultFlag = false;
                }
              }
            })
          }

        }else{

          if(this.baseInfoData.mesQcTourinspLinemList){
            this.baseInfoData.mesQcTourinspLinemList.forEach(item=>{
              let flag = true;
              item.mesQcTourinspProjectsList.forEach(item=>{
                let measuredValue  = item.measuredValue;
                if(item.valueType==2){
                  item.individualJudgment =measuredValue=='PASS'?1:2;


                  if(measuredValue!='PASS'){
                    flag = false;
                    resultFlag = false;
                  }
                }else{

                  if((item.upperValue&&item.upperValue!='')&&(!item.downValue||item.downValue=="")){
                    if(measuredValue<=item.upperValue){
                      item.individualJudgment = 1;
                    }else{
                      item.individualJudgment = 2;
                      flag = false;
                      resultFlag = false;
                    }
                  }else if((!item.upperValue||item.upperValue=='')&&(item.downValue&&item.downValue!="")){
                    if(measuredValue>=item.downValue){
                      item.individualJudgment = 1;
                    }else{
                      item.individualJudgment = 2;
                      flag = false;
                      resultFlag = false;
                    }
                  }else if(measuredValue<=item.upperValue&&measuredValue>=item.downValue){
                    item.individualJudgment = 1;
                  }else{
                    item.individualJudgment = 2;
                    flag = false;
                    resultFlag = false;
                  }
                }

              })

              item.inspectResult = flag?1:2;
            })
          }

        }



        this.baseInfoData.inspectResult = resultFlag?1:2;

      },

      //保存
      saveDataBtn(){
        let data = this.baseInfoData;
        putAction('/mes-quality/mesQcTourInspectTask/saveTourInspect',data).then(res=>{
          if(res.success){
            this.$message.success("保存成功");
            this.initData();
          }else{
            this.$message.warning(res.msg);
          }
        })
      },


      //提交
      submitData(){
          let flag = true;
          let data = this.baseInfoData;

          console.log(data.inspectResult)
        console.log(data.changeCondition)
          if(data.inspectResult==2){
            if(!data.changeCondition||data.changeCondition===''){
              flag = false;
              this.$message.error("检验结论不合格，整改情况必填！")
            }
          }

          if(flag){
            putAction('/mes-quality/mesQcTourInspectTask/updateTourInspect',data).then(res=>{
              if(res.success){
                this.$message.success("提交成功");
                this.backToIndex();
              }else{
                this.$message.warning(res.msg);
              }
            })
          }
      },






    },
  };
</script>
<style scoped>
  @import "~@assets/less/common.less";
  .title {
    padding: 8px 12px;
    background: #fafafa;
  }
  .title:not(:first-child) {
    margin-top: 25px;
  }
  /deep/ .poros-form{
    margin-top:15px;
  }
  /deep/ .poros-table-body {
    overflow-x: auto !important;
  }
  /deep/ .poros-col{
    min-height: 54px;
  }
</style>
